// add1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <list>
#include <algorithm>
#include <iostream>

using namespace std;

template <class T>
inline void PRINT_ELEMENTS (const T& coll, const char *optcstr = "")
{
	typename T::const_iterator pos;

	std::cout << optcstr;
	for (pos=coll.begin(); pos!=coll.end(); ++pos)
	{
		std::cout << *pos << ' ';
	}
	std::cout << std::endl;
}

class AddValue
{
private:
	int theValue;
public:
	AddValue(int v): theValue(v){}
	void operator()(int &elem) const
	{
		elem += theValue;
	}

};
int _tmain(int argc, _TCHAR* argv[])
{
	list <int> coll;
	for (int i=1; i<=9; i++)
	{
		coll.push_back(i);
	}

	PRINT_ELEMENTS(coll, "initialized");

	for_each(coll.begin(), coll.end(), AddValue(10));

	PRINT_ELEMENTS(coll, "after adding 10: ");

	for_each(coll.begin(), coll.end(), AddValue(*coll.begin()));

	PRINT_ELEMENTS(coll, "after adding first element: ");
    cin.get();
	return 0;
}

